package org.ruanjj.baseknowleadgedemo;

import java.lang.reflect.Field;

public class Main {
    public static void main(String[] args) throws CloneNotSupportedException, NoSuchFieldException, IllegalAccessException {
        Address address = new Address("testClone");
        InstanceObjectByClone instanceObjectByClone = new InstanceObjectByClone(address);
        InstanceObjectByClone instanceObjectByCloneTest = (InstanceObjectByClone)instanceObjectByClone.clone();
        System.out.println(instanceObjectByCloneTest.getAddress());
        //深拷贝这个address对象是复制出来的副本和原本对象并不指向同一个地址
        System.out.println(instanceObjectByClone.address == instanceObjectByCloneTest.address);

        //反射给类的变量复制或者修改私有的变量值
        Employee e = new Employee("test1",12);
        Field employeeFields = Employee.class.getDeclaredField("flag");
        employeeFields.setAccessible(true);
        employeeFields.set(e, "test");
        System.out.println(Employee.getFlag());
    }
}
